package visitor;

import operatori.Cat;
import operatori.Minus;
import operatori.Operator;
import operatori.Plus;
import operatori.Produs;
import operatori.Putere;
import Arbore.Nod;
import functii.Functie;
import functii.elementare.Constanta;
import functii.elementare.Necunoscuta;
import functii.trigonometrice.Cos;
import functii.trigonometrice.Sin;

public class ToStringVisitor extends Visitor {
	String s;

	public void visitare(Operator o) {
		if(o.getfStang()!=null){
			visit(o.getfStang());
			String s1 = this.s;
			s = o.concatTermeni(s1, null);
		}
	}
	
	public void visitare (Functie f) {
		if(f.getfStang()!=null){
			visit(f.getfStang());
			String s1 = this.s;
			s = f.concatTermeni(s1);
		}
	}
	public void visitare(Plus p) {
		if(p.getfStang()!=null && p.getfDrept()!=null){
			visit(p.getfStang());
			String s1 = this.s;
			visit(p.getfDrept());
			String s2 = this.s;
			s = p.concatTermeni(s1, s2);
		}
	}

	public void visitare(Minus m) {
		if(m.getfStang()!=null && m.getfDrept()!=null){
			visit(m.getfStang());
			String s1 = this.s;
			visit(m.getfDrept());
			String s2 = this.s;
			s = m.concatTermeni(s1, s2);
		}
	}

	public void visitare(Cat m) {
		if(m.getfStang()!=null && m.getfDrept()!=null){
			visit(m.getfStang());
			String s1 = this.s;
			visit(m.getfDrept());
			String s2 = this.s;
			s = m.concatTermeni(s1, s2);
		}
		
	}

	public void visitare(Produs p) {
		if(p.getfStang()!=null && p.getfDrept()!=null){
			visit(p.getfStang());
			String s1 = this.s;
			visit(p.getfDrept());
			String s2 = this.s;
			s = p.concatTermeni(s1, s2);
		}
	}
	
	public void visit(Plus p) {
		visitare(p);
	}
	public void visit(Minus m) {
		visitare(m);
	}
	
	public void visit(Cat m) {
		visitare(m);
	}
	
	public void visit(Produs p) {
		visitare(p);
	}
	public void visit(Necunoscuta n) {
		this.s="x";
	}

	public void visit(Constanta c) {
		this.s=Double.toString(c.getCt());
	}

	public void visit(Sin s) {
		visitare((Sin)s);
	}

	public void visit(Cos c) {
		visitare((Cos)c);
	}

	public void visit(Nod n) {
		if(n instanceof Operator)
			visit((Operator)n);
		if(n instanceof Necunoscuta)
			visit((Necunoscuta)n);
		if(n instanceof Constanta)
			visit((Constanta)n);
		if(n instanceof Sin)
			visit((Sin)n);
		if(n instanceof Cos)
			visit((Cos)n);
		if(n instanceof Plus)
			visit((Plus)n);
		if(n instanceof Minus)
			visit((Minus)n);
		if(n instanceof Cat)
			visit((Cat)n);
		if(n instanceof Produs)
			visit((Produs)n);
		if(n instanceof Putere)
			visit((Putere)n);
	}
	
	public void visit(Operator p) {
		if((p.getfStang()!=null)&&(p.getfDrept()!=null)) {
			visit(p.getfStang());
			String s1=this.s;
			visit(p.getfDrept());
			String s2=this.s;
			s=p.concatTermeni(s1,s2);
		}
	}
	
	public void visit(Functie f) {
		if(f.getfStang()!=null) {
			visit(f.getfStang());
			String s1=this.s;
			s=f.concatTermeni(s1);
		}
	}
	
	public String getS() {
		return s;
	}

	public void setS(String s1) {
		this.s = s1;
	}

	public ToStringVisitor() {
		this.s="";
	}

	public ToStringVisitor(String s1) {
		super();
		this.s = s1;
	}

}
